package com.wanfajie.smsdistribute.db.bean.template

import com.j256.ormlite.field.DatabaseField

data class Placeholder(
        @DatabaseField(columnName = TEMPLATE_ID, foreign = true, canBeNull = false)
        val template: TemplateBean? = null,

        @DatabaseField(columnName = POS_START, canBeNull = false)
        val startPos: Int = 0,

        @DatabaseField(columnName = POS_STOP, canBeNull = false)
        val stopPos: Int = 0
) {
    companion object {
        const val TEMPLATE_ID = "template_id"
        const val POS_START = "start_pos"
        const val POS_STOP = "stop_pos"
        const val PRIMARY_KEY = "pk"
    }

    @DatabaseField(columnName = PRIMARY_KEY, generatedId = false, canBeNull = false, id = true)
    val primaryKey = if (template != null) "${template.id}_${startPos}_$stopPos" else ""

    val pair by lazy {
        startPos to stopPos
    }
}